package com.llbnk.springcoding.migrate;

import com.llbnk.springcoding.dao.UserNewDao;
import com.llbnk.springcoding.dao.UserOldDao;
import com.llbnk.springcoding.mapper.user_info.UserMapper;
import com.llbnk.springcoding.mapper.user_info_core.UserInfoMapper;
import com.llbnk.springcoding.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;

@Component
public class UserDataBaseMigrate extends AbsMigrateProcess<User>{

    public static final String USER_MIGRATE = "user";

    @Autowired
    private UserNewDao userNewDao;

    @Autowired
    private UserOldDao userOldDao;

    @Override
    Object selectOld(String methodName, Object... data) {
        Method method = ReflectionUtils.findMethod(userOldDao.getClass(), methodName,null);
        return ReflectionUtils.invokeMethod(method,userOldDao,data);
    }

    @Override
    Object selectNew(String methodName, Object... data) {
        Method method = ReflectionUtils.findMethod(userOldDao.getClass(), methodName,null);
        return ReflectionUtils.invokeMethod(method,userOldDao,data);
    }

    @Override
    void addOld(User data) {
        userOldDao.insert(data);
    }

    @Override
    void addNew(User data) {
        userNewDao.insert(data);
    }

    @Override
    public String type() {
        return USER_MIGRATE;
    }
}
